package MR;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.db.DBConfiguration;
import org.apache.hadoop.mapreduce.lib.db.DBOutputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

public class ContentJob {
    public static void main(String[]args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = new Configuration();
        DBConfiguration.configureDB(conf,"com.mysql.jdbc.Driver","jdbc:mysql://uplooking05/test?useUnicode=true&characterEncoding=UTF8","root","root");
//        conf.set("fs.defaultFS", "hdfs://ns1");
        Job job = Job.getInstance(conf);

        job.setJarByClass(ContentJob.class);

        job.setMapperClass(ContentMapper.class);
        job.setReducerClass(ContentReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        TextInputFormat.setInputPaths(job,new Path("e:/contents.txt"));
        DBOutputFormat.setOutput(job,"content","content","count");
        job.waitForCompletion(true);

    }

}
